<?php
namespace app\admin\controller;
use think\Db;
use lib\Curl;
class Aboutus extends Base{
    //广告图
    public function intro_banner(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('intro_banner')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['banner']=$param['banner'];
            $data['title_en']=$param['title_en'];
            $res= Db::name('intro_banner')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200,'msg' => '更新成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    
    //公司简介
    public function introduce(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('introduce')->where('id',1)->find();
            $data['intro_item']=json_decode($data['intro_item']);
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['seo_keywords']=$param['seo_keywords'];
            $data['seo_description']=$param['seo_description'];
            $data['title']=$param['title'];
            $data['subtitle']=$param['subtitle'];
            $data['introduce']=$param['introduce'];
            $data['intro_item']=json_encode($param['intro_item']);
            $data['detail']=html_entity_decode($param['detail']);
            $data['seo_keywords']=$param['seo_keywords'];
            $data['seo_description']=$param['seo_description'];
            $res= Db::name('introduce')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200,'msg' => '更新成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    //企业文化设置
    public function culture_set(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('culture_l')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['title_en']=$param['title_en'];
            $data['img']=$param['img'];
            $data['seo_keywords']=$param['seo_keywords'];
            $data['seo_description']=$param['seo_description'];
            $res=Db::name('culture_l')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function culture_list(){
        $list=Db::name('culture')->order('id desc')->paginate(10);
        $counts=Db::name('culture')->count();
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function culture_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['icon']=$param['icon'];
            $data['title']=$param['title'];
            $data['slogan']=$param['slogan'];
            $data['time'] =time();
            $data['uptime'] =time();
            $res= Db::name('culture')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
            
        }
    }
    public function culture_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('culture')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['icon']=$param['icon'];
            $data['title']=$param['title'];
            $data['slogan']=$param['slogan'];
            $data['uptime'] =time();
            $res=Db::name('culture')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
            
        }
    }
    public function culture_del(){
        $param = input('post.');
        $res= Db::name('culture')->where(array('id'=>$param['id']))->delete();
        return json(['code' => 200,'msg' => '删除成功']);

    }
    public function culture_dels(){
        $param = input('post.');
        $res= Db::name('culture')->where(array('id'=>$param['id']))->delete();
        return json(['code' => 200,'msg' => '删除成功']);

    }
    // 大记事
    public function biglog_cate(){
        $list=Db::name('biglog_year')->where('state',1)->order('id desc')->paginate(10);
        $counts=Db::name('biglog_year')->where('state',1)->count();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function biglog_cate_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['year']=$param['year'];
            $res=Db::name('biglog_year')->insert($data);
            if($res){
                return json(['code' => 200,'msg' => '成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    public function biglog_cate_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('biglog_year')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['year']=$param['year'];
            $res= Db::name('biglog_year')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200,'msg' => '更新成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    public function biglog_cate_del(){
        $param = input('post.');
        $res= Db::name('biglog_year')->where(array('id'=>$param['id']))->update(['state'=>3]);
        return json(['code' => 200,'msg' => '删除成功']);

    }
    public function biglog_list(){
        $keyword=input('get.keyword');
        if (!empty(input('get.fromtime'))) {
            $fromtime=strtotime(input('get.fromtime'));
        }else{
            $fromtime=0;
        }
        if (!empty(input('get.totime'))) {
            $totime=strtotime(input('get.totime'))+86400;
        }else{
            $totime=time();
        }
        $map = [
            ['a.time', '>', $fromtime],
            ['a.time', '<', $totime]
        ];
        array_push($map,['a.state','<',3]);
        $list=Db::name('biglog')->alias('a')->join('biglog_year b', 'a.year_id = b.id','LEFT')->field('a.*,b.year')->where($map)->where('a.year_month','like',"%{$keyword}%")->order('a.id desc')->paginate(10);
        $counts=Db::name('biglog')->alias('a')->join('biglog_year b', 'a.year_id = b.id','LEFT')->field('a.*,b.year')->where($map)->where('a.year_month','like',"%{$keyword}%")->count();
        $this->assign('keyword',input('get.keyword'));
        $this->assign('fromtime',input('get.fromtime'));
        $this->assign('totime',input('get.totime'));
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function biglog_add(){
        if(request()->isGet()){
            $year=Db::name('biglog_year')->where('state',1)->order('id desc')->select();
            $this->assign('year',$year);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['year_id']=$param['year_id'];
            $data['log']=$param['log'];
            $data['year_month']=$param['year_month'];
            $data['time'] =time();
            $data['uptime'] =time();
            $res= Db::name('biglog')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
            
        }
    }
    public function biglog_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('biglog')->where('id',$param['id'])->find();
            $year=Db::name('biglog_year')->where('state',1)->order('id desc')->select();
            $this->assign('year',$year);
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['year_id']=$param['year_id'];
            $data['log']=$param['log'];
            $data['year_month']=$param['year_month'];
            $data['uptime'] =time();
            $res=Db::name('biglog')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
            
        }
    }
    public function biglog_del(){
        $param = input('post.');
        $res= Db::name('biglog')->where(array('id'=>$param['id']))->update(['state'=>3]);
        return json(['code' => 200,'msg' => '删除成功']);

    }
    public function biglog_dels(){
        $param = input('post.');
        $res= Db::name('biglog')->where(array('id'=>$param['id']))->update(['state'=>3]);
        return json(['code' => 200,'msg' => '删除成功']);

    }

    public function biglog_set(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('biglog_l')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['title_en']=$param['title_en'];
            $data['img']=$param['img'];
            $data['seo_keywords']=$param['seo_keywords'];
            $data['seo_description']=$param['seo_description'];
            $res=Db::name('biglog_l')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    // 荣誉资质
    public function honour_list(){
        $list=Db::name('honour')->where('state',1)->order('id desc')->paginate(10);
        $counts=Db::name('honour')->where('state',1)->count();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function honour_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['img']=$param['img'];
            $data['title']=$param['title'];
            $data['sort']=$param['sort'];
            $data['time']=time();
            $data['uptime']=time();
            $res= Db::name('honour')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function honour_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('honour')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['img']=$param['img'];
            $data['title']=$param['title'];
            $data['sort']=$param['sort'];
            $data['uptime']=time();
            $res= Db::name('honour')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function honour_del(){
        $param = input('post.');
        $res= Db::name('honour')->where(array('id'=>$param['id']))->update(['state'=>3]);
        return json(['code' => 200,'msg' => '删除成功']);

    }
    // 合作伙伴
    public function partner_list(){
        $list=Db::name('partner')->where('state',1)->order('id desc')->paginate(10);
        $lists=Db::name('partner')->where('state',1)->select();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('lists',$lists);
        return $this->fetch();
    }
    public function partner_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['img']=$param['img'];
            $data['title']=$param['title'];
            $data['sort']=$param['sort'];
            $data['time']=time();
            $data['uptime']=time();
            $res=Db::name('partner')->insert($data);
            if($res){
                return json(['code' => 200,'msg' => '成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    public function partner_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('partner')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['img']=$param['img'];
            $data['title']=$param['title'];
            $data['sort']=$param['sort'];
            $data['uptime']=time();
            $res= Db::name('partner')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200,'msg' => '更新成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    public function partner_del(){
        $param = input('post.');
        $res= Db::name('partner')->where(array('id'=>$param['id']))->update(['state'=>3]);
        return json(['code' => 200,'msg' => '删除成功']);

    }
    public function partner_set(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('partner_title')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['subtitle']=$param['subtitle'];
            $data['seo_keywords']=$param['seo_keywords'];
            $data['seo_description']=$param['seo_description'];
            $res=Db::name('partner_title')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
}
